<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>

<div style="margin:20px 0;"></div>
<div class="easyui-panel">
	<div style="padding:10px 60px 20px 60px">
    	<form id="roleForm" name="roleForm" method="post" action="<c:url value='/roleinf/saveRoleInf.do'/>">
    		<!-- 非顶级机构 或者修改角色时，角色所属机构存入隐藏域-->
    		<c:if test="${entity.supInsUuid != null}">
		    	<input type="hidden" id="ins_uuid" name="ins_uuid" value="${entity.INS_UUID}"/>
    		</c:if>
    		<!-- 顶级机构新增角色时 -->
    		<c:if test="${entity.supInsUuid == null}">
    			<c:if test="${entity.ROLE_UUID != null}">
    				<input type="hidden" id="ins_uuid" name="ins_uuid" value="${entity.INS_UUID}"/>
    			</c:if>
    			<c:if test="${entity.ROLE_UUID == null}">
		    		<input type="hidden" id="ins_uuid" name="ins_uuid"/>
    			</c:if>
    		</c:if>
	    	<input type="hidden" name="role_uuid" value="${entity.ROLE_UUID}"/>
	    	<input type="hidden" name="role_tp" value="${entity.ROLE_TP}"/>
	    	<input type="hidden" id="roleName" value="${entity.ROLE_NAME}"/>
	    	<table cellpadding="5" style="width:100%;width:100%">
	    		<tr>
	    			<td>角色名称:</td>
	    			<td><input class="easyui-textbox" type="text" id="role_name" name="role_name" data-options="required:true" value="${entity.ROLE_NAME}"/></td>
	    		</tr>
	    		<c:if test="${entity.supInsUuid == null}">
		    		<tr>
		    			<td>所属机构:</td>
		    			<td>
		    				<input class="easyui-textbox" type="text" readonly="readonly" id="inst_name" value="${entity.INST_NAME}"/>
	    					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctBtn">选择</a>
	    				</td>
		    		</tr>
	    		</c:if>
	    		<tr>
	    			<td>角色描述:</td>
	    			<td><input class="easyui-textbox" name="role_desc" data-options="multiline:true" value="${entity.ROLE_DESC}"/></td>
	    		</tr>
	    	</table>
	    	<div style="text-align:center;padding:5px">
		    	<!-- <a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-save" onclick="saveRole()">保存</a>
		    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-back" onclick="back()">返回</a> -->
		    	<jiepos:buttonDetailTag menuCode="${menuCode}" formId="roleForm"></jiepos:buttonDetailTag>
		    </div>
    	</form>
    </div>
</div>
<script type="text/javascript">
	/*选择按钮*/
	$("#selelctBtn").click(function(){
		showInsTree(selected, $("#ins_uuid").val());
	});
	
	/*确定按钮回调*/
	function selected(nodes){
		if(nodes && nodes.length > 0){
			$("#inst_name").textbox("setValue", nodes[0].NAME);
			$("#ins_uuid").val(nodes[0].ID);
		}
	}
	
	function saveRole(){
		if(!$("#roleForm").form("validate")){
			return;
		};
		var isExist = false;
		if($("#roleName").val() !== $("#role_name").val()){
			$.jpajax({
				url: "roleNameIsExist.do",
				data: {roleName: $("#role_name").val(), insUuid: $("#ins_uuid").val()},
				success: function(result){
					isExist = result;
				}
			});
		}
		if(isExist === false){
			$("#roleForm").submit();
		}else{
			$.jpmessage.warning("角色名称已经存在");
		}
	}
</script>